/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Views.GestionRestaurateur;

import Model.Expertise;
import Model.Gender;
import Model.Restaurateur;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author ibrahim
 */
public class RestaurateurTableModel extends AbstractTableModel {

    private List<Restaurateur>db;
    private String[] colNames = {"ID","FirstName","LastName","Gender","Expertise","CandianCitizen","PemanantCode"};
    public  RestaurateurTableModel (){};
        
    
    public void setData(List<Restaurateur>db){
       this.db=db;
    }
    @Override
    public int getRowCount() {
        return db.size();
    }
   
    @Override
    public int getColumnCount() {
        return 7;
    }

    @Override
    public String getColumnName(int column) {
        return colNames[column]; //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
       switch(columnIndex){
            case 0:
                return Integer.class;
            case 1:
                return String.class;
            case 2:
                return String.class;
            case 3:
                return Gender.class;
            case 4:
                return Expertise.class;
            case 5:
                return Boolean.class;
            case 6: 
                return String.class;
            default:
                return null;
        } 
    }
    

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 1:
                return true;
            case 2:
                return true;
            case 3:
                return true;
            case 4:
                return true;
            case 5:
                return true;
            case 6:
                return true;
            default:
                return false;
        }
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        if (db==null) return;
        Restaurateur restaurateur = db.get(rowIndex);
         switch(columnIndex){
            case 1:
                  restaurateur.setFname((String)aValue);
                break;
            case 2:
                  restaurateur.setLname((String)aValue);
                break;
            case 3:
                  restaurateur.setGender((Gender)aValue);
                break;
            case 4:
                  restaurateur.setExpertise((Expertise)aValue);
                break;
            case 5:
                  restaurateur.setCitizen((Boolean)aValue);
                break;
            case 6:
                  restaurateur.setPermanantCode((String)aValue);
                break;
            default:
                return;
         }
    }
    

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Restaurateur restaurateur = db.get(rowIndex);
        switch(columnIndex){
            case 0:
                return restaurateur.getId();
            case 1:
                return restaurateur.getFname();
            case 2:
                return restaurateur.getLname();
            case 3:
                return restaurateur.getGender();
            case 4:
                return restaurateur.getExpertise();
            case 5:
                return restaurateur.isCitizen();
            case 6: 
                return restaurateur.getPermanantCode();
        }
    return null;
}
}